package com.dongdongshop.controller;

import com.dongdongshop.data.Result;
import com.dongdongshop.enums.ResultEnums;
import com.dongdongshop.pojo.PageResult;
import com.dongdongshop.pojo.TbSeller;
import com.dongdongshop.pojo.TbTypeTemplate;
import com.dongdongshop.service.TbSellerService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("TbSeller")
public class TbSellerController {

    //注入service
    @DubboReference
    private TbSellerService tbSellerService;

    //查询商家全部数据(要求分页)
    @ResponseBody
    @RequestMapping("TbSellershowall")
    public Result TbSellershowall(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "3") Integer pageSize, TbSeller tbSeller) {
        try {
            PageResult<TbSeller> result = tbSellerService.TbSellershowall(pageNum, pageSize, tbSeller);
            return Result.response(ResultEnums.SHOW_SUCCESS).setData(result);
        } catch (Exception e) {
            return Result.response(ResultEnums.SHOW_ERROR);
        }
    }

    //查询单个商家全部数据
    @ResponseBody
    @RequestMapping("TbSellershowbysellerId")
    public Result TbSellershowbysellerId(String sellerId) {
        try {
            TbSeller result = tbSellerService.TbSellershowbysellerId(sellerId);
            return Result.response(ResultEnums.SHOW_SUCCESS).setData(result);
        } catch (Exception e) {
            return Result.response(ResultEnums.SHOW_ERROR);
        }
    }

    //修改单个商家数据
    @ResponseBody
    @RequestMapping("updateTbSeller")
    public Result updateTbSeller(TbSeller tbSeller) {
        try {
            tbSellerService.updateTbSeller(tbSeller);
            return Result.response(ResultEnums.UPDATE_SUCCESS);
        } catch (Exception e) {
            return Result.response(ResultEnums.UPDATE_ERROR);
        }
    }

}
